#pragma config(Sensor, in1,    lineFollower_L,      sensorLineFollower)
#pragma config(Sensor, in2,    lineFollower_R,      sensorLineFollower)
#pragma config(Sensor, dgtl1,  enc_lift,            sensorRotation)
#pragma config(Sensor, dgtl2,  bump_claw_1,         sensorTouch)
#pragma config(Sensor, dgtl3,  bump_claw_2,         sensorTouch)
#pragma config(Motor,  port2,           motor_L,       tmotorNormal, openLoop)
#pragma config(Motor,  port3,           motor_R,       tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port6,           servo_claw_L,  tmotorServoStandard, openLoop)
#pragma config(Motor,  port7,           servo_claw_R,  tmotorServoStandard, openLoop)
#pragma config(Motor,  port8,           motor_lift_L,  tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port9,           motor_lift_R,  tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*
 * This file is the main competition program. I split this file from the others, so it would be simple to switch between
 * competition mode and a controllable mode for testing (i.e. turning off autonomous mode, etc), but still use the same functions.
 */

#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"   //Main competition background code...do not modify!

/*
 * #include "filename" makes RobotC copy in that file, as if you'd typed everything in that file instead of typing include "filename"
 *
 * If you had a file named bob.h that had "int bob(){ return 5; }", and put it here,
 * you would then have a function named bob that you could use below, or in any of the files included after bob. Think of it as a way
 * of seperating your code. My favorite here being "ChangableConstants.h". It is included first, so
 * all the variables from it are useable anywhere.
 */
#include "ChangableConstants.h"
#include "ZFunctions.h"
// Notice again that ZController is included after ZFunctions. This is because ZController uses the functions in ZFunctions, and it wouldn't be able to get them if it were before they existed.
#include "ZController.h"

/////////////////////////////////////////////////////////////////////////////////////////
//
//                          Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()
{
  // Set the difference from lift's current height to its old height to zero (it's at its previous height)
	liftENC = 0;
	// Open the claw
	openClaw();

	// liftStartsAtTop is in ChangeableConstants. Depending on if it is true or false,
	// set liftClicks(the current position of the lift) to either the maximum or minimum value.
	if(liftStartsAtTop)
	{
		liftClicks = maxLiftClicks;
	}
	else
	{
		liftClicks = 0;
	}
	// Just a note, entire if/else statement could be writen as:
	// liftClicks = (liftStartsAtTop)?maxLiftClicks:0;
	//
	// i.e. variable = (true/false statement)?ifTrue:ifFalse;
	// thus, if the true/false statement is true, variable will be set to ifTrue, otherwise, it will be set to ifFalse.
}

// This task is run when the competition goes to user control mode.
task usercontrol()
{
	/*
	 * This basicly says "while true is true, do everything inside, and only stop doing it when
	 * true is not true (this never happens, so it will loop infinintely, or until the task is killed by the vex people.
	 */
	while (true)
	{
		/*
		 * mainLoop is found in ZController.h
		 * mainLoop sets all motor speeds and such based on the status of the buttons on the
		 * Vex controller (i.e. if a button is down, it closes the claw)
		 */
		mainLoop();
	}

	/*
	 * You will notice that the default template has another task, autonomous. However, since I wanted to use the same code for both competition and non-competition code, I moved that task into
	 * "ZController.h", and then included it. Including a file acts as though I typed it in this file, so it runs as if it were actually here.
	 */
}
